package com.bj58.analysis.tools.common;

import java.util.HashMap;
import java.util.Map;

import org.apache.commons.lang.StringUtils;

import com.bj58.analysis.tools.common.bean.InfoData;

/**
 * @description 用于解析帖子内容
 * @author tzc
 *
 */
public class InfoDataUtils {

	/**
	 * @description 将帖子内容解析成一个帖子属性对象
	 * @param infoDataLine
	 *            帖子内容
	 * @return 返回一个帖子属性对象
	 */
	public static InfoData parserToInfoData(String infoDataLine) {
		InfoData infoData = null;
		if (StringUtils.isNotBlank(infoDataLine)) {
			String[] arrys = infoDataLine.split("_");
			if (arrys.length > 3) {
				infoData = new InfoData();
				infoData.setInfoType(arrys[0]);
				infoData.setUserType(arrys[1]);
				infoData.setUserId(arrys[2]);
				infoData.setInfoId(arrys[3]);
				Map<String, String> efMap = null;
				String extField = null;
				if (arrys.length > 4) {
					for (int i = 4; i < arrys.length; i++) {
						if (arrys[i].indexOf(":") > -1) {
							extField = arrys[i];
							break;
						}
					}
				}

				if (StringUtils.isNotBlank(extField)) {
					efMap = new HashMap<String, String>();
					String[] es = extField.split("@");
					for (String kv : es) {
						String[] ss = kv.split(":");
						if (ss.length > 1) {
							String k = ss[0];
							String v = ss[1];
							efMap.put(k, v);
						}
					}
				}

				if (efMap != null && efMap.size() != 0) {
					infoData.setExtFeildsMap(efMap);
				}
			}
		}
		return infoData;
	}

	
}
